import Cookies from 'js-cookie'
import { getStore } from '@/util/store'

const TokenKey = 'x-access-token'
const TokenTimeKey = 'x-access-token-time'

// var inFifteenMinutes = new Date(new Date().getTime() + 60 * 2 * 1000);
export function getToken() {
    return Cookies.get(TokenKey)
}

export function setToken(token) {
    var tokenTime = getStore({ name: TokenTimeKey });
    // console.log(tokenTime);
    var inFifteenMinutes = new Date(new Date().getTime() + tokenTime * 1000);
    return Cookies.set(TokenKey, token, { expires: inFifteenMinutes })
}

export function removeToken() {
    return Cookies.remove(TokenKey)
}

export function getTokenTimeKey() {
    return TokenTimeKey
}